﻿//-----------------------------------------------------------------------
// <copyright file="IClientAuthorizationService.cs" company="Alan Rodrigues">
//     Copyright (c) Alan Rodrigues. All rights reserved.
// </copyright>
// <developed>Alan Rodrigues (operninha@gmail.com)</developed>
//-----------------------------------------------------------------------
using System;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace Authorization
{
    [ServiceContract(Name = "ClientAuthorizationService", Namespace = "http://authorizationservices/v1")]
    [DataContractFormat(Style = OperationFormatStyle.Document)]
    public interface IClientAuthorizationService
    {
        ///<summary>
        /// Gets <see cref="OperationCollection"/> from <see cref="ApplicationCollection"/> to authenticated user
        ///</summary>
        ///<param name="applicationName"> <see cref="Application"/> name</param>
        /// <param name="scopeName">returns operationIds from the <see cref="Scope"/>, null will return from azmanApplication root</param>
        ///<returns><see cref="OperationCollection"/> from choosen azmanApplication and scope</returns>
        [OperationContract(Name = "GetOperationsForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        OperationCollection GetOperationsForUser(string applicationName, string scopeName);

        [OperationContract(Name = "GetOperationNamesForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        string[] GetOperationNamesForUser(string applicationName, string scopeName);


        [OperationContract(Name = "GetTasksForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        TaskCollection GetTasksForUser(string applicationName, string scopeName);

        [OperationContract(Name = "GetTaskNamesForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "GET",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetTaskNamesForUser(string userName, string applicationName, string scopeName);


        [OperationContract(Name = "GetRoleAssignmentsForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        RoleAssignmentCollection GetRoleAssignmentsForUser(string applicationName, string scopeName);

        [OperationContract(Name = "GetRoleAssignmentNamesForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        string[] GetRoleAssignmentNamesForUser(string applicationName, string scopeName);

        [OperationContract(Name = "IsUserInRoleAssignment")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        bool IsUserInRoleAssignment(string applicationName, string scopeName, string roleName);

        [OperationContract(Name = "IsUserInTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "GET",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool IsUserInTask(string userName, string applicationName, string taskName, string[] scopeNames);

        [OperationContract(Name = "GetAllAssignedScopesForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        string[] GetAllAssignedScopesForUser(string applicationName);

        [OperationContract(Name = "GetAllAssignedScopesForUserWithFilter")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        string[] GetAllAssignedScopesForUser(string applicationName, string filterPattern);


        [OperationContract(Name = "GetAssignedScopesPageForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        AuthorizationResponseWithCursor<string[]> GetAssignedScopesPageForUser(string applicationName, int pageSize, string cursor);
        
        [OperationContract(Name = "AccessCheck")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
        bool AccessCheck(string applicationName, int operationId, string scopeName);

        [OperationContract(Name = "AccessCheckByName")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        [XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
        bool AccessCheck(string applicationName, string operationName, string scopeName);

        [OperationContract(Name = "BulkAccessCheck")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        int[] AccessCheck(string applicationName, int[] operationIds, string[] scopeNames);

        [OperationContract(Name = "BulkAccessCheckByName")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        OperationCollection AccessCheck(string applicationName, string[] operationNames, string[] scopeNames);

        [OperationContract(Name = "BulkAccessCheckWithRules")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        //[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool AccessCheck(string applicationName, int operationId, string scopeName, string[] variableNames, object[] variableValues);
    }
   
}
